package com.zhixue.study.api;


import com.zhixue.exception.ZhixuePlusException;
import com.zhixue.model.PageResult;
import com.zhixue.study.model.dto.*;
import com.zhixue.study.model.po.XcCourseTables;
import com.zhixue.study.service.MyCourseTablesService;
import com.zhixue.study.util.SecurityUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 李力
 * @version 1.0
 * @description 我的课程表接口
 * @date 2025/05/14 9:40
 */


@Slf4j
@RestController
@RequestMapping
public class MyCourseTablesController {

    @Autowired
    private MyCourseTablesService myCourseTablesService;

    //添加选课
    @PostMapping("/choosecourse/{courseId}")
    public XcChooseCourseDto addChooseCourse(@PathVariable("courseId") Long courseId) {
        //获取用户
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        if (user == null) {
            throw new ZhixuePlusException("请先登录");
        }
        String id = user.getId();
        return myCourseTablesService.addChooseCourse(id, courseId);
    }

    //查询学习资格
    @PostMapping("/choosecourse/learnstatus/{courseId}")
    public XcCourseTablesDto getLearnstatus(@PathVariable("courseId") Long courseId) {
        //获取用户
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        if (user == null) {
            throw new ZhixuePlusException("请先登录");
        }
        String id = user.getId();
        return myCourseTablesService.getLearningStatus(id, courseId);
    }

    @GetMapping("/mycoursetable")
    public PageResult<XcCourseTables> mycoursetable(MyCourseTableParams params) {
        return null;
    }
}
